home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Demos / Simpsons Cartoon Studio™ Demo / Simpdata / simpmain / 00011_stackManager parent.ls < prev    next >
Encoding:
Text File  |  1996-09-06  |  5.1 KB  |  163 lines

  1. property numberOfChannels, baseStackSpr, moverStackSpr, holderStackSpr, STKorgH, STKorgV, STKminV, STKmaxV, STKiconHeight, STKiconGap, stackList, channelsInStack
  2. global currentFrame, dispatchTable, dirtyFlag
  3.  
  4. on birth me
  5.   init(me)
  6.   return me
  7. end
  8.  
  9. on init me
  10.   set numberOfChannels to 12
  11.   set baseStackSpr to 36
  12.   set moverStackSpr to 48
  13.   set holderStackSpr to 1
  14.   set STKorgH to 20
  15.   set STKorgV to 17
  16.   set STKiconHeight to 30
  17.   set STKiconGap to 1
  18.   set STKminV to STKorgV + (STKiconHeight / 2)
  19.   repeat with i = 36 to 48
  20.     puppetSprite(i, 1)
  21.   end repeat
  22. end
  23.  
  24. on update me
  25.   set channelsInStack to count(dispatchTable)
  26.   set STKmaxV to STKorgV + (channelsInStack * (STKiconHeight + STKiconGap)) - (STKiconHeight / 2) - 1
  27.   set stackList to []
  28.   repeat with theLayerNum = 1 to channelsInStack
  29.     set dispatchCell to getAt(dispatchTable, theLayerNum)
  30.     set dispatchGroup to getAt(dispatchCell, 2)
  31.     set iconCast to the number of cast ("icon." & dispatchGroup)
  32.     if iconCast = -1 then
  33.       set iconCast to the number of cast "icon.default"
  34.     end if
  35.     set iconSpr to theLayerNum + baseStackSpr - 1
  36.     set curCell to [iconCast, iconSpr]
  37.     add(stackList, curCell)
  38.   end repeat
  39.   set curPos to 0
  40.   set curCount to 1
  41.   repeat with theChannel = 36 to 47
  42.     if curCount <= channelsInStack then
  43.       set curCast to getAt(getAt(stackList, curCount), 1)
  44.       set the castNum of sprite theChannel to curCast
  45.       set the locH of sprite theChannel to STKorgH + (STKiconHeight / 2)
  46.       set the locV of sprite theChannel to STKorgV + (STKiconHeight / 2) + (curPos * (STKiconHeight + STKiconGap))
  47.     else
  48.       set the locH of sprite theChannel to -1000
  49.     end if
  50.     set curPos to curPos + 1
  51.     set curCount to curCount + 1
  52.   end repeat
  53. end
  54.  
  55. on shuffleStack me
  56.   set whichSpr to the clickOn
  57.   set offset to the locV of sprite whichSpr - STKorgV
  58.   set sourceLayer to 1 + (offset / (STKiconHeight + STKiconGap))
  59.   set sourceCast to the castNum of sprite whichSpr
  60.   set the castNum of sprite moverStackSpr to sourceCast
  61.   set the locH of sprite moverStackSpr to STKorgH + (STKiconHeight / 2)
  62.   set the locH of sprite whichSpr to -1000
  63.   set oldSpace to sourceLayer
  64.   set curSpace to sourceLayer
  65.   set stackChanged to 0
  66.   set loopCheck to #outer
  67.   repeat while the mouseDown
  68.     set loopCheck to #outer
  69.     if inside(point(the mouseH, the mouseV), rect(20, 20, 50, 389)) then
  70.       set loopCheck to #inner
  71.       set vMouse to the mouseV
  72.       if vMouse < STKminV then
  73.         set vMouse to STKminV
  74.       end if
  75.       if vMouse > STKmaxV then
  76.         set vMouse to STKmaxV
  77.       end if
  78.       set the locV of sprite moverStackSpr to vMouse
  79.       set offset to vMouse - STKorgV
  80.       set newPos to 1 + (offset / (STKiconHeight + STKiconGap))
  81.       updateStage()
  82.       if newPos = curSpace then
  83.         next repeat
  84.       else
  85.         set stackChanged to 1
  86.         set dirtyFlag to 1
  87.       end if
  88.       set moveCell to getAt(stackList, curSpace)
  89.       deleteAt(stackList, curSpace)
  90.       addAt(stackList, newPos, moveCell)
  91.       if newPos > curSpace then
  92.         repeat with x = curSpace to newPos - 1
  93.           put x
  94.           puppetSound("stack snd")
  95.           set curSpr to getAt(getAt(stackList, x), 2)
  96.           set curV to the locV of sprite curSpr - 1
  97.           repeat with y = 1 to 10
  98.             set the locV of sprite curSpr to curV - (y * 3)
  99.             updateStage()
  100.           end repeat
  101.         end repeat
  102.       else
  103.         repeat with x = curSpace down to newPos + 1
  104.           put x
  105.           puppetSound("stack snd")
  106.           set curSpr to getAt(getAt(stackList, x), 2)
  107.           set curV to the locV of sprite curSpr + 1
  108.           repeat with y = 1 to 10
  109.             set the locV of sprite curSpr to curV + (y * 3)
  110.             updateStage()
  111.           end repeat
  112.           updateStage()
  113.         end repeat
  114.       end if
  115.     end if
  116.     if loopCheck = #inner then
  117.       set oldSpace to curSpace
  118.       set curSpace to newPos
  119.     end if
  120.   end repeat
  121.   set the locH of sprite moverStackSpr to -1000
  122.   set the locH of sprite whichSpr to STKorgH + (STKiconHeight / 2)
  123.   set the locV of sprite whichSpr to STKorgV + (STKiconHeight / 2) + ((curSpace - 1) * (STKiconHeight + STKiconGap))
  124.   if sourceLayer <> curSpace then
  125.     set moveCell to getAt(dispatchTable, sourceLayer)
  126.     deleteAt(dispatchTable, sourceLayer)
  127.     addAt(dispatchTable, curSpace, moveCell)
  128.   end if
  129.   showFrame(playbackMgr, currentFrame, 0)
  130.   if not stackChanged then
  131.     doSelectClip(me)
  132.   end if
  133.   startTimer()
  134. end
  135.  
  136. on doSelectClip me
  137.   set whichSpr to the clickOn
  138.   set cNum to the castNum of sprite whichSpr
  139.   set the itemDelimiter to "."
  140.   set castRoot to item 2 of the name of cast cNum
  141.   set the itemDelimiter to ","
  142.   set cnt to 0
  143.   set scoreChannel to 0
  144.   repeat with curRec in dispatchTable
  145.     set cnt to cnt + 1
  146.     if castRoot = getAt(curRec, 2) then
  147.       set scoreChannel to cnt + 2
  148.       exit repeat
  149.     end if
  150.   end repeat
  151.   if scoreChannel <> 0 then
  152.     set onStage to 0
  153.     set cNum to 0
  154.     if the locH of sprite scoreChannel > 0 then
  155.       set cNum to the castNum of sprite scoreChannel
  156.       set onStage to 1
  157.     end if
  158.     if onStage then
  159.       selectClip(editMgr, scoreChannel)
  160.     end if
  161.   end if
  162. end
  163.